/*	
	This program is free software; you can redistribute it and/or modify 
	it under the terms of the GNU General Public License as published by 
	the Free Software Foundation; either version 2 of the License, or 
	any later version.

    	This program is distributed in the hope that it will be useful, but 
	WITHOUT ANY WARRANTY; without even the implied warranty of 
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
	General Public License for more details.

    	You should have received a copy of the GNU General Public License 
	along with this program; if not, write to the Free Software 
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
	USA
*/

#include<driver.h>

// GESTIONE VIDEO IN MODALITA' TESTO
char memoria_virtuale[25][80][2];
char *memoria_video;
int pagina=0;
/* memoria video fisica PAGINE

- Pagina 0: 0xB8000	|	Pagina 4: 0xBC000
- Pagina 1: 0xB9000	|	Pagina 5: 0xBD000
- Pagina 2: 0xBA000	|	Pagina 6: 0xBE000
- Pagina 3: 0xBB000	|	Pagina 7: 0xBF000

*/
void init_video() {
	init_memoria();
	riga=0; colonna=0;
	clear_screen();
}

void init_memoria() {
	memoria_video=(char*)0xb8000;
}

void set_page(int numero_pagina) { 
	char *puntatore=(char *)0xb8000;
	int i=0;
	for(i=0;i<numero_pagina;i++) {
		puntatore=puntatore+0x1000;
	}
	memoria_video=(char*)puntatore;
}

void add_char(int x,int y,char carattere,char attributo) {
	memoria_virtuale[x][y][0]=carattere;
	memoria_virtuale[x][y][1]=attributo;
}

void trasloca() {
	init_memoria();
	int i,j;
	for(i=0;i<25;i++) {
		for(j=0;j<80;j++) {
			*memoria_video++ = memoria_virtuale[i][j][0];
			*memoria_video++ = memoria_virtuale[i][j][1];
		}
	}
}

void clear_memoria() {
	int i,j;
	for(i=0;i<25;i++) {
		for(j=0;j<80;j++) {
			memoria_virtuale[i][j][0]=' ';
			memoria_virtuale[i][j][1]=0x7;
		}
	}
}

void clear_screen() {
	riga=0; colonna=0;
	clear_memoria();
	trasloca();
}

void scroll() {
	int i,j;
	char riga[80];
	for(j=0;j<23;j++) {
		for(i=0;i<80;i++) {
			memoria_virtuale[j][i][0]=memoria_virtuale[j+1][i][0];
			memoria_virtuale[j][i][1]=memoria_virtuale[j+1][i][1];
		}
	}
	for(i=0;i<80;i++) {add_char(23,i,' ',0x7);}
	for(i=0;i<80;i++) {add_char(24,i,' ',0x7);}
	trasloca();
}
